package action.adapter;

import java.util.ArrayList;

import action.newelifile.R;
import action.pojo.LocalFilePojo;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class HistoryFileAdapter extends BaseAdapter{

	LayoutInflater layoutInflater;
	int layoutId;
	ArrayList<LocalFilePojo> array;
	ViewHolder holder;
	Context context;

	public HistoryFileAdapter(Context context, int textViewResourceId, ArrayList<LocalFilePojo> array) {
		this.context = context;
		this.layoutId = textViewResourceId;
		this.array = array; 
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {   
		final LocalFilePojo files = array.get(position);
		if(convertView==null){
			holder = new ViewHolder();
			LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView=layoutInflater.inflate(layoutId, parent,false);

			holder.iv = (ImageView) convertView.findViewById(R.id.historyIcon);
			holder.tv = (TextView) convertView.findViewById(R.id.historyText);
			holder.path = (TextView) convertView.findViewById(R.id.historyPath);

			convertView.setTag(holder);
		}else{
			holder = (ViewHolder)convertView.getTag();
		}

		/*if(files.getFileItem()!=null){
	        if(files.getIcon()!=null)
	        	holder.iv.setImageDrawable(files.getIcon());    
		    if (files.getName()!=null)
		    	holder.tv.setText(files.getName());
		    if (files.getPath()!=null) 
		    	holder.path.setText(files.getPath());
        }*/
		if(files.getFileItem().getName()!=null){
			if(files.getIcon()!=null)
				holder.iv.setImageDrawable(files.getIcon());
			if (files.getFileItem().getName()!=null)
				holder.tv.setText(files.getFileItem().getName());
			if (files.getFileItem().getPath()!=null) 
				holder.path.setText(files.getFileItem().getPath());
		}
		return convertView;
	}

	public static class ViewHolder{
		ImageView iv;
		TextView tv,path;
	}

	@Override
	public int getCount() {
		return array.size();
	}
	@Override
	public Object getItem(int position) {
		return array.get(position);
	}
	@Override
	public long getItemId(int position) {
		return position;
	}
}
